﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Renci.iRods.Common;

namespace Renci.iRods.Data
{
    public abstract class MetaDataItem : DataItem
    {
        private string _metadataType;

        private MetadataCollection _metaData;
        /// <summary>
        /// Gets the meta data of the data item.
        /// </summary>
        public MetadataCollection MetaData
        {
            get
            {
                if (this._metaData == null)
                {
                    this._metaData = new MetadataCollection(this.Connection, this.MetadataFullName, this._metadataType, this.MetadataQuery, this.MetadataProjector);
                    this._metaData.Refresh();
                }
                return this._metaData;
            }
        }

        protected abstract string MetadataFullName { get; }

        protected abstract IRodsQuery MetadataQuery { get; }

        protected abstract Func<IRodsDataReader, MetaData> MetadataProjector { get; }

        public MetaDataItem(IRodsConnection connection, string metadataType)
            : base(connection)
        {
            this._metadataType = metadataType;
        }
    }
}
